package com.ruoyi.system.controller;

import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.MedPre;
import com.ruoyi.system.domain.Medicine;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MedPo;
import com.ruoyi.system.service.IMedPoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购_药品对应Controller
 * 
 * @author yangxp
 * @date 2020-08-08
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/medicine/medPo" )
public class MedPoController extends BaseController {

    private final IMedPoService iMedPoService;

    /**
     * 查询采购_药品对应列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedPo medPo)
    {
        startPage();
        LambdaQueryWrapper<MedPo> lqw = new LambdaQueryWrapper<MedPo>();
        if (StringUtils.isNotBlank(medPo.getMedName())){
            lqw.like(MedPo::getMedName ,medPo.getMedName());
        }
        if (medPo.getMedWeight() != null){
            lqw.eq(MedPo::getMedWeight ,medPo.getMedWeight());
        }
        if (medPo.getMedCostPrice() != null){
            lqw.eq(MedPo::getMedCostPrice ,medPo.getMedCostPrice());
        }
        if (medPo.getMedMarketPrice() != null){
            lqw.eq(MedPo::getMedMarketPrice ,medPo.getMedMarketPrice());
        }
        List<MedPo> list = iMedPoService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出采购_药品对应列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPo:export')" )
    @Log(title = "采购_药品对应" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MedPo medPo) {
        LambdaQueryWrapper<MedPo> lqw = new LambdaQueryWrapper<MedPo>(medPo);
        List<MedPo> list = iMedPoService.list(lqw);
        ExcelUtil<MedPo> util = new ExcelUtil<MedPo>(MedPo. class);
        return util.exportExcel(list, "medPo" );
    }

    /**
     * 获取采购_药品对应详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPo:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMedPoService.getById(id));
    }

    /**
     * 新增采购_药品对应
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPo:add')" )
    @Log(title = "采购_药品对应" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedPo medPo) {
        return toAjax(iMedPoService.save(medPo) ? 1 : 0);
    }

    /**
     * 修改采购_药品对应
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPo:edit')" )
    @Log(title = "采购_药品对应" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedPo medPo) {
        return toAjax(iMedPoService.updateById(medPo) ? 1 : 0);
    }

    /**
     * 删除采购_药品对应
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPo:remove')" )
    @Log(title = "采购_药品对应" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iMedPoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }



}
